<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>订单</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <link rel="stylesheet" href="/css/app.css"/>
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script type="text/javascript" src="/js/json2.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
    <script type="text/javascript" src="/js/Cart.js"></script>
    <style>

    </style>
</head>

<body class="wx">

<div class="header">
    <div class="left"><i class="icon-back"></i>菜单</div>
    <div class="title">确认订单</div>
</div>

<div class="order-body">
    
    <div id="order-list" class="food-list">
        <div id="repeat-food-item" class="food-item" style="display: none;">
            <div class="menu-name">天目湖剁椒鱼头</div>
            <span class="price-wrapper"><span class="unitPrice">￥78</span><span class="count">*3</span></span>
            <span class="price">￥200</span>
        </div>
    </div>

    <div class="summary">
        <div class="summary-line">
            <span class="summary-left">小计:</span>
            <span id="total" class="summary-right">￥400</span>
        </div>
        <div class="summary-line">
            <span class="summary-left">优惠:</span>
            <span class="summary-right">无</span>
        </div>
        <div id="final-total" class="total">总计：374.88</div>
        <button id="confirm" class="btn book">付款</button>
    </div>

</div>

<script th:inline="javascript">
    (function(){
        'use strict';
        $.get('/api/getorder/user/' + 97,function(data){
            var $orderList = $('#order-list');
            var total = 0;
            var menus = data.menus;
            $.each(menus,function(index,item){
                var $item = cloneItem();
                var unitPrice = item.foodDetail.unitPrice;
                var count = item.count;
                var price = unitPrice * count;
                $item.find('.menu-name').text(item.foodDetail.name);
                $item.find('.unitPrice').text(unitPrice);
                $item.find('.count').text('x'+count);
                $item.find('.price').text(price);
                total += price;

                $orderList.append($item);
            });

            $('#total').text('￥'+ total);
            $('#final-total').text('总计: ￥'+total);
        });


        $('#confirm').click(function(){
            //付款
            //console.log('pay');
//            common.toast("我是金山顺!!!");

           var $floatUI = common.showLoading("加载中...(^^)");
           // common.dismissLoading($floatUI);
        });

        var $repeatItem = undefined;
        function cloneItem(){
            if(!$repeatItem){
                $repeatItem = $('#repeat-food-item');
            }
            var $item = $repeatItem.clone();
            $item.attr('id',Date.now());
            $item.show();
            return $item;
        }

    })();
</script>
</body>

</html>